<?
	layout("/inc/win_layout.html",{title:sysTitle}){
?>
<link rel="stylesheet" href="static/uploadify/uploadify.css" type="text/css"></link>
<script type="text/javascript" src="static/uploadify/jquery.uploadify.min.js"></script>
<script type="text/javascript" src="static/utf8-jsp/ueditor.config.js"></script>
<script type="text/javascript" src="static/utf8-jsp/ueditor.all.js"></script>
<script type="text/javascript" src="static/utf8-jsp/lang/zh-cn/zh-cn.js"></script>
<script type="text/javascript" src="static/utf8-jsp/third-party/video-js/video.js"></script>
<script type="text/javascript" src="static/My97DatePicker/WdatePicker.js"></script>
<!-- <script src="static/laydate/laydate.js"></script> --> <!-- 改成你的路径 -->

<div class="panel ">
	<div class="panel-body pan" style="height: 485px;overflow: auto;">
		<form action="#" class="form-horizontal">
			<div class="form-body pal">
				<div class="row" style="margin-top:-15px; margin-bottom: 10px;">
					<div class="col-lg-6"
						style="width: 410px; float:left;  margin-right:-30px; display:inline;">
						<label for="inputUsername" class="col-md-3 control-label">用户名(英文字母、下划线、数字,20字符以内)
							<span class='require' id="yonghu">*</span> </label>
						<div class="col-md-9">
							<div class="input-icon">
								<input id="username" onchange="onPanduan(this.value);"
									type="text" class="form-control" value="" />
							</div>
						</div>
					</div>
					<div class="col-lg-6"
						style="width: 410px; float:right; display:inline;">
						<label for="inputUsername" class="col-md-3 control-label">密码（6-20字符以内）
							<span class='require' id="mima">*</span> </label>
						<div class="col-md-9">
							<div class="input-icon">
								<input id="password" type="password" class="form-control"/>
							</div>
						</div>
					</div>
				</div>
				<div class="row" style="margin-bottom: 10px;">
					<div class="col-lg-6"
						style="width: 410px; float:left; margin-right:-30px; display:inline;">
						<label for="inputUsername" class="col-md-3 control-label">昵称(汉字、英文字母、数字及下划线,20字符以内)
							<span class='require' id="yonghu">*</span> </label>
						<div class="col-md-9">
							<div class="input-icon">
								<input id="nickName" type="text" class="form-control" value="" />
							</div>
						</div>
					</div>
					<div class="col-lg-6"
						style="width: 410px; float:right; display:inline;">
						<label for="inputUsername" class="col-md-3 control-label">手机号
							<span class='require' >*</span> </label>
						<div class="col-md-9">
							<div class="input-icon">
								<input id="telephone" type="text" class="form-control" />
							</div>
						</div>
					</div>
				</div>
				<div class="row" style="margin-bottom: 10px;">
					<div class="col-lg-6"
						style="width: 410px; float:left; margin-right:-30px; display:inline;">
						<label for="inputUsername" class="col-md-3 control-label">真实姓名(汉字、英文字母、数字及下划线,20字符以内)
							<span class='require' id="yonghu">*</span> </label>
						<div class="col-md-9">
							<div class="input-icon">
								<input id="realName" type="text" class="form-control" value="" />
							</div>
						</div>
					</div>
					<div class="col-lg-6" style="width: 410px; float:right; display:inline;">
						<label for="inputUsername" class="col-md-3 control-label">邮箱
							<span class='require'>*</span> </label>
						<div class="col-md-9">
							<div class="input-icon">
								<input id="email" type="text" class="form-control" />
							</div>
						</div>
					</div>
				</div> 	
				<div class="row" style="margin-bottom: 10px;">
					<div class="col-lg-6" style="width: 410px; float:left; margin-right:-30px; display:inline;">
						<label for="inputUsername" class="col-md-3 control-label">用户头像<span
						class='require'>*</span> </label>
						<div class="col-md-9">
							<div style="display:inline " id="cover"></div>
							<input type="button" class="btn btn-primary" style="width: 70px;height: 30px;padding: 0;background-color: #4cae4c;border-color: #4cae4c;" onclick="upImages()" value="上传头像"  />
							<textarea id="uploadImage" name="uploadImage" style="display: none;"></textarea>
							<input id="coverImg" type="hidden" class="form-control" value="" />
						</div>
					</div>
					<div class="col-lg-6" style="width: 410px; float:right; display:inline;">
						<label for="inputUsername" class="col-md-3 control-label">性别
						<span class='require'>*</span> </label>
						<div class="col-md-9">
							<div class="input-icon">
								<select id="gender" class="form-control">
									<option value="0">未知</option>
									<option value="1">女</option>
									<option value="2">男</option>
								</select>
							</div>
						</div>
					</div>
					
				</div> 
				<div class="row" style="margin-bottom: 10px;">
					<div class="col-lg-6" style="width: 410px; float:left; margin-right:-30px; display:inline;">
						<label for="inputUsername" class="col-md-3 control-label">用户类型<span
						class='require'>*</span> </label>
						<div class="col-md-9">
							<select id="type" class="form-control">
								<option value="1">教师用户</option>
							</select>
						</div>
					</div>
				</div>
				<div class="row" style="margin-bottom: 10px;">
					<label for="inputUsername" class="col-md-3 control-label">个性签名（500字以内）
						<span class='require'></span> </label>
					<div class="col-md-12">
						<div class="input-icon">
							<textarea id="signature"  rows="3" cols="20" class="form-control" ></textarea> 
						</div>
					</div>
				</div>
				<div class="row" style="margin-bottom: 10px;">
					<label for="inputUsername" class="col-md-3 control-label">简介（500字以内）
						<span class='require'></span> </label>
					<div class="col-md-12">
						<div class="input-icon">
							<textarea id="description"  rows="3" cols="20" class="form-control" ></textarea> 
						</div>
					</div>
				</div>
			</div>
		</form>
	</div>
</div>
<?} ?>
<script>
	$(function() {
		_editor = UE.getEditor('uploadImage');
	    _editor.ready(function (){
	        //设置编辑器不可用(事实上不可以设置不可用...所以注释掉,以观后效)
	        _editor.setDisabled();
	        //隐藏编辑器,因为只使用上传功能
	        _editor.hide();
	        //侦听图片上传
	  	 	_editor.addListener('beforeInsertImage',function(t,arg){
	  	 			for(var i=0;i<arg.length;i++){
	  	 				var urlPath = arg[i].src;
	  	 				$("#coverImg").val(urlPath);
						$("#cover").html("<a href="+urlPath+" download='w3logo'><img src='"+urlPath+"' width='30' height='30' /></a>");
	  	 			}
	        });
	        //侦听文件上传
		   	 _editor.addListener('afterUpfile',function(t,arg){
		   	 	
		   	 });
	   });
	});
	
	function save() {
		if ($.trim($("#username").val()).length < 1) {
			layer.msg('请输入用户名！');
			return null;
		}
		
		
		var username=$("#username").val(); //    
	    var re =/^[\w]{1,20}$/;
		if (!re.test(username)) {
			layer.msg('用户名:只允英文字母、数字及下划线,限制20个字符以内。');
			return null;
		}
		
		if ($.trim($("#password").val()).length < 1) {
			layer.msg('请输入密码！');
			return null;
		}
		if($("#password").val().length<6 || $("#password").val().length>20){
				layer.msg('密码:6-20位之间');
				return null;
			}
		
		if ($.trim($("#realName").val()).length < 1) {
			layer.msg('请输入真实姓名！');
			return null;
		}
		var realName=$("#realName").val(); //    
	    var re =/^[\u4e00-\u9fa5_a-zA-Z0-9]{1,20}$/;
		if (!re.test(realName)) {
			layer.msg('真实姓名:只允许汉字、英文字母、数字及下划线。20字以内');
			return null;
		}
		if ($.trim($("#nickName").val()).length < 1) {
			layer.msg('请输入昵称！');
			return null;
		}
		
		var nickName=$("#nickName").val(); //    
	    //var re =/^[\u0391-\uFFE5\w]{1,20}$/;
		if (!re.test(nickName)) {
			layer.msg('昵称:只允许汉字、英文字母、数字及下划线。20字以内');
			return null;
		}
		
		if ($.trim($("#coverImg").val()).length < 1) {
			layer.msg('请上传头像！');
			return null;
		}
		var telephonetext=$.trim($("#telephone").val()); //    
       	var telephonere =/^1[012345789]\d{9}$/;
		if (!telephonere.test(telephonetext)) {
			layer.msg('手机号格式不正确！');
			return null;
		}
	   	var text=$.trim($("#email").val()); //    
       	var re =/^([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})$/;
		if (!re.test(text)) {
			layer.msg('邮箱格式不正确！');
			return null;
		}
		
		if($("#signature").val()!='' && $("#signature").val().length>500){
			layer.msg('个性签名：500字以内');
			return null;
		}
		if($("#description").val()!='' && $("#description").val().length>500){
			layer.msg('简介：500字以内');
			return null;
		}
		$.ajax({
			type : "post",
			url : "./userSave.do",
			data : {
				"id" : $("#id").val(),
				"description" : $("#description").val(),
				"email" : $("#email").val(),
				"gender" : $("#gender").val(),
				"nickName" : $("#nickName").val(),
				"password" : $("#password").val(),
				"realName" : $("#realName").val(),
				"signature" : $("#signature").val(),
				"telephone" : $("#telephone").val(),
				"type" : $("#type").val(),
				"username" : $("#username").val(),
				"avatarImg" : $("#coverImg").val(),
			},
			dataType : "json",
			async : false,
			success : function(data) {
				if(data[0].result=='success'){
					var index = parent.layer.getFrameIndex(window.name);
					parent.layer.msg('注册成功，审核中');
					parent.layer.close(index);	
				}else{
					layer.msg(data[0].msg);
				}
			},
			error : function(data) {
				alert("请求失败");
			}
		});
	}
	
function onPanduan(name) {
	$.ajax({
		type : "post",
		url : "./UserPanDuan.do",
		data : {
			"username" : name
		},
		dataType : "json",
		async : false,
		success : function(data) {
			if (data[0].tishi == 0) {
				layer.msg("用户名已经存在");
				$("#username").val("");
			}
		}
	});
}

//上传图片
function upImages() {
	var myFiles = _editor.getDialog("insertimage");
  		myFiles.open();
}
</script>


